package station;

/**
 * Vorlesung: Verteilte Systeme
 * Aufgabe  : 04
 * 
 * @author Benjamin Burchard
 * @author Tell Mueller-Pettenpohl
 * 
 */

import java.io.IOException;
import java.net.NetworkInterface;

import timeDivisionMultipleAccess.exceptions.FrameTimeoutException;

public class StationStarter {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if (args.length > 0 && !args[0].equals("--help")) {
			String iface = args[0];
			int udpPortSrc = Integer.parseInt(args[1]);
			String mcastAddr = args[2];
			int mcastPort = Integer.parseInt(args[3]);
			int udpPortSink = Integer.parseInt(args[4]);
			String ifaceAddr = null;
			try {
				ifaceAddr = NetworkInterface.getByName(iface)
						.getInetAddresses().nextElement().getHostAddress();
				System.out.println(NetworkInterface.getByName(iface)
						.getInetAddresses().nextElement());
				Station station = new Station(ifaceAddr, udpPortSrc, mcastAddr,
						mcastPort);
				station.startReceiver(udpPortSrc, udpPortSink);
				station.receiveData();
			} catch (FrameTimeoutException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else {
			System.err
					.println("Usage: java station.Station <interface> <udp source port> <multicast ip> <multicast port> <udp sink port");
		}
	}
}
